/**
 * @file state.h
 * @brief Main header file, contain all global definition, data structure, and function
 *
 * @author Ricky Hariady (ricky.hariady@enter.web.id)
 *
 * @date 7/10/2013
 */

#define STATE_MAX_STATE       4       ///< Maximum Card State Manager

/********************************/
/*        Data Structure        */
/********************************/

/**
 * @brief structure of Card State Manager
 */
struct state_struct
{
        uint16_t        current;     ///< pointer to current DF header
        uint16_t        currentKey;    ///< pointer to current Key EF header
        uint16_t        currentRecord;  ///< Record number of currently selected EF
        uint8_t         securityState;  ///< security state currently active
};

/**************************/
/*        Variable        */
/**************************/


/**************************/
/*        Function        */
/**************************/

int stateInitialize();

/**
 * @brief verify security state with PIN
 *
 * Verify security state using PIN
 *
 * @param newState the number of state to be activated
 * @return Result
 */
int stateChangeState(int newState);

/**
 * @brief verify security state with PIN
 *
 * Verify security state using PIN
 *
 * @param PIN PIN Number
 * @return File System Result enum
 */
int stateVerify(uint8_t *PIN);

/**
 * @brief Set current file
 *
 * Set state of current file to a new file
 *
 * @param newDF index of current DF in file table
 * @return Result
 */
int stateSetCurrent(uint16_t newfile);

/**
 * @brief Set current EFKey
 *
 * Set state of current EFKey to a new EFKey
 *
 * @param newEFKey index of current EFKey in file table
 * @return Result
 */
int stateSetCurrentKey(uint16_t newKey);

/**
 * @brief Get current file
 *
 * Get index of current selected file
 *
 * @return current DF index
 */
uint16_t stateGetCurrent();

/**
 * @brief Get current security state
 *
 * Get current security state
 *
 * @return current security state
 */
uint8_t stateGetCurrentSecurity();
